package com.ls.io.rpc.transport;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

public class ResponseContext {

    static ConcurrentHashMap<Long, CompletableFuture> map =  new ConcurrentHashMap<>();


    public static CompletableFuture addRequest(long requestId){
        CompletableFuture response = new CompletableFuture();
        map.putIfAbsent(requestId, response);
        return response;
    }

    public static CompletableFuture getResponse(long requestId){
//        System.out.println("remove: " + requestId);
        CompletableFuture response = map.remove(requestId);
        return response;
    }

}
